\subsection{Definition}
Recall the intermediate value theorem from IA Analysis.
If \( f \colon I \to \mathbb R \) is continuous, where \( I \) is an interval, and \( x < y \) in \( I \) and \( c \in (f(x), f(y)) \), then there exists \( z \in (x,y) \) such that \( f(z) = c \).
An interval in this context is a set \( I \) such that for all \( x<y<z \in \mathbb R \), \( x,z \in I \implies y \in I \).
So the intermediate value theorem essentially states that the continuous image of an interval is an interval.
\begin{example}
	Consider \( [0,1) \cup (1,2] \).
	Let \( f \) be a function from this space to \( \mathbb R \), defined by
	\[
		f(x) = \begin{cases}
			0 & x \in [0,1) \\
			1 & x \in (1,2]
		\end{cases}
	\]
	This is continuous, but the image of \( f \) is not an interval.
\end{example}
\begin{definition}
	A topological space \( X \) is \textit{disconnected} if there exist open subsets \( U, V \) of \( X \) such that \( U \cap V = \varnothing, U \cup V = X \) and \( U, V \neq \varnothing \).
	We say that \( U \) and \( V \) \textit{disconnect} \( X \).
	We say \( X \) is \textit{connected} if \( X \) is not disconnected.
\end{definition}
\begin{theorem}
	Let \( X \) be a topological space.
	Then the following are equivalent.
	\begin{enumerate}
		\item \( X \) is connected;
		\item if \( f \colon X \to \mathbb R \) is continuous, then \( f(X) \) is an interval;
		\item if \( f \colon X \to \mathbb Z \) is continuous, \( f \) is constant.
	\end{enumerate}
\end{theorem}
\begin{proof}
	First we show (i) implies (ii).
	Suppose \( X \) is connected, and \( f \colon X \to \mathbb R \) is continuous, but \( f(X) \) is not an interval.
	Then there exist \( a<b<c \in \mathbb R \) such that \( a,c \in f(X) \) and \( b \not\in f(X) \).
	Let \( x,y \in X \) such that \( f(x) = a, f(y) = c \).
	Let \( U = f^{-1}(-\infty, b), V = f^{-1}(b,\infty) \).
	\( U, V \) are open since \( f \) is continuous.
	\( U, V \) are non-empty since \( x \in U, y \in V \).
	Their intersection is empty since we are taking the preimage of disjoint sets.
	Finally, \( U \cup V = f^{-1}(\mathbb R \setminus b) = X \) since \( b \) is not in the image.
	So \( U, V \) disconnect \( X \), which is a contradiction.

	Now (ii) implies (iii).
	This is immediate since an interval containing an integer must only contain one integer.

	Finally, (iii) implies (i).
	Suppose \( U, V \) disconnect \( X \).
	Let \( f \colon X \to \mathbb Z \) by
	\[
		f(x) = \begin{cases}
			0 & x \in U \\
			1 & x \in V
		\end{cases}
	\]
	For any \( Y \subset \mathbb R \),
	\[
		f^{-1}(Y) = \begin{cases} \varnothing & 0,1 \not\in Y      \\
              U           & 0\in Y, 1\not\in Y \\
              V           & 0\not\in Y, 1\in Y \\
              X           & 0,1 \in Y
		\end{cases}
	\]
	which is open.
	But \( f \) is not constant, so this is a contradiction.
\end{proof}
\begin{corollary}
	Let \( X \subset \mathbb R \).
	Then \( X \) is connected if and only if \( X \) is an interval.
\end{corollary}
\begin{proof}
	Suppose \( X \) is connected.
	Then the inclusion map \( i \colon X \to \mathbb R \) is continuous.
	By the theorem above, \( i(X) = X \) is an interval.
	Conversely, suppose \( X \) is an interval.
	Then, for all continuous \( f \colon X \to \mathbb R \), \( f(X) \) is an interval by the intermediate value theorem.
	Then \( X \) is connected.
\end{proof}
\begin{proof}
	This is an alternative, direct proof that intervals are connected.
	Suppose \( U, V \) disconnect \( X \).
	Then let \( x \in U, y \in V \) such that \( x < y \).
	Let \( z = \sup U \cap [x,y] \).
	This set is non-empty since it contains \( x \) and is bounded above by \( y \).
	So \( z = [x,y] \subset X \).
	We will show \( z \in U \cap V \), which is a contradiction.
	For all \( n \in \mathbb N \), we have \( z - \frac{1}{n} < n \) so there exists \( x_n \in U \cap [x,y] \) which satisfies \( z - \frac{1}{n} < x_n \leq z \).
	Hence \( x_n \to z \).
	Also, \( U = X \setminus V \) is closed, so \( z \in U \).
	In particular, \( z < y \).
	Now, choose \( N \in \mathbb N \) such that \( z + \frac{1}{N} < y \).
	Then for all \( n \geq N \) we have \( z < z + \frac{1}{n} < y \).
	Hence \( z + \frac{1}{n} \in V \).
	However, \( z + \frac{1}{n} \to z \), and \( V \) is closed, so \( z \in V \), which is a contradiction.
\end{proof}

\subsection{Consequences of definition}
\begin{example}
	Any indiscrete topological space is connected.
	Any cofinite topological space on an infinite set is connected.
	The discrete topological space on a set of size at least two is disconnected.
\end{example}
\begin{lemma}
	Let \( Y \) be a subspace of a topological space \( X \).
	Then, \( Y \) is disconnected if and only if there exist open subsets \( U, V \) of \( X \) such that \( U \cap V \cap Y = \varnothing \) and \( U \cup V \supset Y \), and \( U \cap Y \neq \varnothing, V \cap Y \neq \varnothing \).
\end{lemma}
\begin{proof}
	Suppose \( Y \) is disconnected.
	Then there exist open subsets \( U', V' \) of \( Y \) that disconnect \( Y \).
	Then there exist open sets \( U, V \) in \( X \) such that \( U' = U \cap Y \) and \( V' = V \cap Y \).
	Then \( U, V \) satisfy the requirements from the lemma.

	Conversely, suppose \( U, V \) are as given.
	Then, let \( U' = U \cap Y, V' = V \cap Y \).
	They are open in \( Y \) by the definition of the subspace topology, and they disconnect \( Y \).
\end{proof}
\begin{remark}
	In the above lemma, we say subsets \( U, V \) of \( X \) disconnect \( Y \).
\end{remark}
\begin{proposition}
	Let \( Y \) be a subspace of a topological space \( X \).
	If \( Y \) is connected, then so is \( \overline Y \).
\end{proposition}
\begin{proof}
	Suppose \( \overline Y \) is disconnected.
	Then there exist open sets \( U, V \) in \( X \) which disconnect \( \overline Y \).
	Then \( U \cap V \cap Y \subset U \cap V \cap \overline Y = \varnothing \) by definition.
	Hence \( U \cap V \cap Y = \varnothing \).
	Also, \( U \cup V \supset \overline Y \supset Y \).
	So \( U, V \) disconnect \( Y \) unless \( U \cap Y = \varnothing \) or \( V \cap Y = \varnothing \).
	But \( Y \) is connected, so without loss of generality let \( V \cap Y = \varnothing \).
	Then \( Y \subset X \setminus V \) and \( X \setminus V \) is closed, so \( \overline Y \subset X \setminus V \).
	Hence \( V \cap \overline Y = \varnothing \).
	This is a contradiction since \( U, V \) disconnect \( \overline Y \).
\end{proof}
\begin{remark}
	More generally, if \( Y \subset Z \subset \overline Y \), and \( Y \) is connected, then \( Z \) is connected.
	This is since \( \mathrm{cl}_Z(Y) = \mathrm{cl}_X(Y) \cap Z = Z \).
\end{remark}
\begin{theorem}
	Let \( f \colon X \to Y \) be a continuous function between topological spaces.
	If \( X \) is connected, then so is \( f(X) \).
\end{theorem}
\begin{proof}
	Let \( U, V \) be open subsets of \( Y \) which disconnect \( f(X) \).
	For \( x \in X \), \( f(x) \in f(X) \subset U \cup V \).
	Hence, \( f^{-1}(U) \cup f^{-1}(V) = X \).
	Also, if \( x \in f^{-1}(U) \cap f^{-1}(V) \) then \( f(x) \in U \cap V \cap f(X) = \varnothing \).
	This is a contradiction, so \( f^{-1}(U) \cap f^{-1}(V) = \varnothing \).
	Since \( f \) is continuous, \( f^{-1}(U), f^{-1}(V) \) are open in \( X \).
	Since \( U \cap f(X) \neq \varnothing \) and \( V \cap f(X) \neq \varnothing \), \( f^{-1}(U) \neq \varnothing \) and \( f^{-1}(V) \neq \varnothing \)
	So \( f^{-1}(U), f^{-1}(V) \) disconnect \( X \).
\end{proof}
\begin{remark}
	This shows that connectedness is a topological property.
	If \( X, Y \) are homeomorphic spaces, then \( X \) is connected if and only if \( Y \) is connected.
	Further, note that if \( f \colon X \to Y \) is continuous and \( A \subset X \) and \( A \) is connected, then \( f(A) \) is connected.
	This can be shown by restricting \( f \) to the domain \( A \).
\end{remark}
\begin{corollary}
	Any quotient of a connected topological space is connected.
\end{corollary}
\begin{example}
	Let
	\[ Y = \qty{\qty(x, \sin\frac{1}{x}) \colon x > 0} \subset \mathbb R^2 \]
	This space is connected; the function \( f \colon (0, \infty) \to \mathbb R^2 \) defined by \( f(x) = \qty(x,\sin \frac{1}{x}) \) is continuous.
	So we have that \( Y = \Im f \) is connected.
	Hence, \( \overline Y \) is connected.
	We claim that
	\[ Z \equiv Y \cup \qty{(0,y) \colon y \in [-1,1]} = \overline Y \]
	Indeed, given \( y \in [-1,1] \), for all \( n \in \mathbb N \) we have that \( (0, \frac{1}{n}) \) is mapped to \( (n,\infty) \) by \( x \to \frac{1}{x} \), so by the intermediate value theorem there exists \( x_n \in \qty(0, \frac{1}{n}) \) such that \( \sin \frac{1}{x_n} = y \).
	Hence,
	\[ \qty(x_n, \sin \frac{1}{x_n}) = (x_n, y) \to (0,y) \in \overline Y \]
	So \( Y \subset Z \subset \overline Y \).
	If we can show \( Z \) is closed, \( Z = \overline Y \) since \( \overline Y \) is the smallest closed superset of \( Y \).
	Suppose \( (x_n, y_n) \in Z \) for all \( n \in \mathbb N \), and \( (x_n, y_n) \to (x,y) \) in \( \mathbb R^2 \).
	Since \( y_n \in [-1,1] \) and \( y_n \to y \), we have \( y \in [-1,1] \).
	If \( x = 0 \), we have \( (x,y) \in Z \).
	If \( x \neq 0 \), then \( x_n \to x \) implies \( x_n \neq 0 \) for all sufficiently large \( n \).
	Hence \( y_n = \sin \frac{1}{x_n} \) for all sufficiently large \( n \).
	Thus
	\[ (x_n, y_n) \to \qty(x, \sin \frac{1}{x}) \in Z \]
\end{example}
\begin{lemma}
	Let \( X \) be a topological space and \( \mathcal A \) be a family of connected subsets of \( X \).
	Suppose that \( A \cap B \neq \varnothing \) for all \( A, B \in \mathcal A \).
	Then \( \bigcup_{A \in \mathcal A} A \) is connected.
\end{lemma}
\begin{proof}
	Let \( Y = \bigcup_{A \in \mathcal A} A \), and let \( f \colon Y \to \mathbb Z \) be a continuous function.
	We must show that \( f \) is constant.
	For all \( A \in \mathcal A \), \( \eval{f}_A \colon A \to \mathbb Z \) is continuous and hence constant, since \( A \) is connected.
	For all \( A, B \in \mathcal A \), \( A \cap B \neq \varnothing \) hence \( \eval{f}_A \) and \( \eval{f}_B \) are both constant and have the same value.
	So \( f \) must be constant, and hence \( Y \) is connected.
\end{proof}
\begin{theorem}
	Let \( X, Y \) be connected topological spaces.
	Then \( X \times Y \) is connected (in the product topology).
\end{theorem}
\begin{proof}
	Without loss of generality, let \( X \neq \varnothing, Y \neq \varnothing \).
	Let \( x_0 \in X \).
	Consider the function \( f \colon Y \to X \times Y \) defined by \( f(y) = (x_0, y) \).
	The components of \( f \) are the functions \( y \mapsto x_0 \) which is continuous as it is constant, and \( y \mapsto y \) which is continuous as it is the identity.
	So \( f \) is continuous.
	Then, the image of \( f \), which is \( \qty{x_0} \times Y \), is connected.
	Similarly, for all \( y \in Y \), \( X \times \qty{y} \) is connected.
	For \( y \in Y \), \( \qty{x_0} \times Y \cap X \times \qty{y} = \qty{(x_0, y)} \neq \varnothing \).
	Hence, \( A_y = \qty{x_0} \times Y \cup X \times \qty{y} \) is connected.
	For all \( y,z \in Y \), \( A_y \cap A_z \supset \qty{x_0} \times Y \) hence \( A_y \cap A_z \neq \varnothing \).
	Hence, \( \bigcup_{y \in Y} A_y = X \times Y \) is connected.
\end{proof}
\begin{example}
	\( \mathbb R^n \) is connected for all \( n \in \mathbb N \).
\end{example}

\subsection{Partitioning into connected components}
\begin{definition}
	Let \( X \) be a topological space.
	We define a relation \( \sim \) on \( X \) by \( x \sim y \) if and only if there exists a connected subset \( A \) of \( X \) such that \( x, y \in A \).
	For all \( x \in X \), \( x \sim x \) since \( \qty{x} \) is connected.
	Symmetry is clear from the definition.
	If \( x \sim y \) and \( y \sim z \) then by definition there exist connected subsets \( A, B \) in \( X \) such that \( x, y \in A \) and \( y, z \in B \).
	In particular, \( A \cap B \) is not empty since \( y \in A \cap B \).
	Hence \( A \cup B \) is connected.
	Since \( A \cup B \) contains \( x, z \), we have \( x \sim z \) as required for transitivity.
	Hence \( \sim \) is an equivalence relation.
	For \( x \in X \), we write \( C_x \) for the equivalence class containing \( x \), called the \textit{connected component} of \( x \).
	The equivalence classes are called \textit{connected components} of \( X \).
\end{definition}
\begin{proposition}
	The connected components of a topological space \( X \) are non-empty, maximal connected subsets of \( X \), they are closed, and they partition \( X \).
\end{proposition}
\begin{proof}
	Let \( C \) be a connected component of \( X \).
	So \( C = C_x \) for some \( x \in X \).
	Then \( x \in C \) hence \( C \neq \varnothing \).
	Suppose \( C \subset A \subset X \) and \( A \) is connected.
	Then for all \( y \in A \), since \( x, y \in A \) we must have \( x \sim y \).
	So \( y \in C \).
	Hence \( A \subset C \), giving \( A = C \).
	For all \( y \in C \), we have \( y \sim x \), so there exists a connected subset \( A_y \subset X \) such that \( x, y \in A_y \).
	Let \( A = \bigcup_{y \in C} A_y \).
	\( A \) is connected since the union of pairwise intersecting connected sets are connected.
	Further \( A \supset C \) so \( A = C \) and \( C \) is connected.
	Since the closure of a connected set is connected, \( \overline C \) is connected.
	But \( \overline C \supset C \), so \( C = \overline C \) is closed.
\end{proof}

\subsection{Path-connectedness}
\begin{definition}
	Let \( X \) be a topological space.
	For points \( x, y \in X \), a \textit{path} from \( x \) to \( y \) in \( X \) is a continuous function \( \gamma \colon [0,1] \to X \) such that \( \gamma(0) = x, \gamma(1) = y \).
	We say that \( X \) is \textit{path-connected} if for all \( x, y \in X \), there exists a path from \( x \) to \( y \) in \( X \).
\end{definition}
\begin{example}
	In \( \mathbb R^n \), \( \mathcal D_r(x) \) is path-connected by a straight line segment between any two points in the ball.
	In particular, let \( \gamma(t) = (1-t)y + tz \).
	This is continuous and lies entirely inside \( \mathcal D_r(x) \), since
	\begin{align*}
		\norm{\gamma(t) = x} & = \norm{(1-t)t + tz - x}           \\
		                     & = \norm{((1-t)y+tz)-((1-t)x+tx)}   \\
		                     & \leq (1-t)\norm{y-x} + t\norm{z-x} \\
		                     & < r
	\end{align*}
	In a similar way, any convex subset of \( \mathbb R^n \) is path-connected.
\end{example}
\begin{theorem}
	If \( X \) is path-connected, \( X \) is connected.
\end{theorem}
\begin{proof}
	Suppose \( X \) is not connected.
	Let \( U, V \) disconnect \( X \).
	Let \( x \in U, y \in V \), and suppose \( \gamma \colon [0,1] \to X \) is continuous with \( \gamma(0) = x \) and \( \gamma(1) = y \).
	Then \( \gamma^{-1}(U) \) and \( \gamma^{-1}(V) \) disconnect \( [0,1] \), which contradicts the connectedness of \( [0,1] \).
\end{proof}
\begin{example}
	The converse is false in general.
	Recall that the space
	\[
		X = \qty{\qty(x, \sin \frac{1}{x}) \colon x > 0} \cup \qty{(0,y) \colon -1 \leq y \leq 1}
	\]
	is connected.
	We will show \( X \) is not path-connected.
	Suppose \( \gamma \colon [0,1] \to X \) is continuous, and \( \gamma(0) = (0,0) \) and \( \gamma(1) = (1, \sin 1) \).
	Let \( \gamma = (\gamma_1, \gamma_2) \), so \( \gamma_1, \gamma_2 \) are continuous functions.
	Suppose \( t \in [0,1] \) such that \( \gamma_1(t) > 0 \).
	Then \( \gamma_1((0,t)) \supset (0, \gamma_1(t)) \) by the intermediate value theorem.
	In particular, there exists \( n \in \mathbb N \) such that \( \frac{1}{2\pi n} \in (0, \gamma_1(t)) \).
	Hence, there exists \( s < t \) such that \( \gamma_1(s) = \frac{1}{2\pi n} \) so \( \gamma_1(s) = 0 \).
	Similarly, \( \frac{1}{2\pi n + \frac{\pi}{2}} \in (0, \gamma_1(t)) \) so there exists a different \( s < t \) such that \( \gamma_1(s) = \frac{1}{2\pi n + \frac{\pi}{2}} \) hence \( \gamma_2(s) = 1 \).
	In both cases, \( \gamma_1(s) > 0 \).
	We can inductively find a sequence \( 1 > t_1 > t_2 > \dots > 0 \) such that \( \gamma_2(t_n) \) alternates between zero and one.
	But then \( t_n \to t \) since it is a decreasing bounded-below sequence, and \( \gamma_2 \) is continuous, so \( \gamma_2(t_n) \to \gamma_2(t) \) which is a contradiction.
\end{example}

\subsection{Gluing lemma}
\begin{lemma}
	Let \( X \) be a topological space.
	Suppose \( X = A \cup B \) where \( A, B \) are closed in \( X \).
	Let \( g \colon A \to Y \) and \( h \colon B \to Y \) be continuous where \( Y \) is a topological space, such that for \( A \cap B \), we have \( g = h \).
	Then \( f \colon X \to Y \) defined by
	\[
		f(x) = \begin{cases}
			g(x) & x \in A \\
			h(x) & x \in B
		\end{cases}
	\]
	is well defined and continuous.
\end{lemma}
\begin{proof}
	First, observe that if \( F \subset A \) and \( F \) is closed in \( A \), then there exists a closed set \( G \) in \( X \) such that \( F = A \cap G \).
	Since \( A \) is closed in \( X \), we must have \( F \) is closed in \( X \).
	The same holds for \( F \subset B \).
	Now, let \( V \) be a closed set in \( Y \).
	Then the inverse image of \( V \) under \( f \) is
	\[
		f^{-1}(V) = (f^{-1}(V) \cap A) \cup (f^{-1}(V) \cap B) = \underbrace{g^{-1}(V)}_{\text{closed in } A} \cup \underbrace{h^{-1}(V)}_{\text{closed in } B}
	\]
	So \( f^{-1}(V) \) is closed in \( X \).
	To prove continuity it suffices to show that the preimage of a closed set is closed, since that implies that the preimage of an open set is open.
\end{proof}
\begin{definition}
	Let \( X \) be a topological space.
	For \( x, y \in X \), we write \( x \sim y \) if there exists a path from \( x \) to \( y \) in \( X \).
	This is an equivalence relation:
	\begin{enumerate}
		\item The constant function shows that \( x \sim x \) for all \( x \).
		\item If \( \gamma \colon [0,1] \to X \) is continuous and \( \gamma(0) = x \), \( \gamma(1) = y \), we define \( t \mapsto \gamma(1-t) \), which is a path from \( y \) to \( x \).
		\item Finally, if \( x \sim y \) and \( y \sim z \), we have continuous functions \( \gamma, \delta \) such that \( \gamma(0) = x, \gamma(1) = y = \delta(0), \delta(1) = z \).
		      Then let
		      \[
			      \eta(t) = \begin{cases}
				      \gamma(2t)   & t \in \qty[0, \frac{1}{2}] \\
				      \delta(2t-1) & t \in \qty[\frac{1}{2}, 1]
			      \end{cases}
		      \]
		      These intervals are closed on \( [0,1] \) and their union is \( [0,1] \).
		      On the intersection, they are equal.
		      By the gluing lemma, \( \eta \) is continuous, and now since \( \eta(0) = x, \eta(1) = z \) we have \( x \sim z \).
	\end{enumerate}
	We call the equivalence classes \textit{path-connected components} of \( X \).
\end{definition}
\begin{theorem}
	Let \( U \) be an open subset of \( \mathbb R^n \).
	Then \( U \) is connected if and only if \( U \) is path-connected.
\end{theorem}
\begin{proof}
	The converse is trivial.
	Suppose \( U \) is connected.
	Without loss of generality, suppose \( U \neq \varnothing \).
	Let \( x_0 \in U \).
	Let \( P = \qty{x \in U \colon x \sim x_0} \) be the equivalence class of \( x_0 \).
	We want to show \( P = U \).
	To do this, we will show that \( P \) is open and closed in \( U \).
	Then, \( P, U \setminus P \) will disconnect \( U \) unless \( P = \varnothing \) or \( P = U \).
	But we know \( x_0 \in P \), hence \( P = U \) will be the only possibility.

	To show \( P \) is open, let \( x \in U \).
	Since \( U \) is open, there exists \( r > 0 \) such that \( \mathcal D_r(x) \subset U \).
	Recall that for all \( y \in \mathcal D_r(x) \), we have \( y \sim x \).
	Now, if \( x \in P \), then we have \( y \sim x \) and \( x \sim x_0 \) so \( y \sim x_0 \).
	So \( \mathcal D_r(x) \subset P \).
	So \( P \) is open.

	Now, if \( x \in U \setminus P \) and \( y \in \mathcal D_r(x) \) has \( y \sim x_0 \), then by transitivity \( x \sim x_0 \).
	But this is a contradiction since \( x \not\in P \).
	Hence \( U \setminus P \) is open.
	So \( P \) is open and closed, so \( P = U \).
\end{proof}
\begin{theorem}
	For \( n \geq 2 \), \( \mathbb R \) and \( \mathbb R^n \) are not homeomorphic.
\end{theorem}
The generalisation \( \mathbb R^m \not\simeq \mathbb R^n \) is true, but significantly harder to prove and outside the scope of this course.
\begin{proof}
	Suppose \( f \colon \mathbb R \to \mathbb R^n \) is a homeomorphism.
	Let \( g = f^{-1} \).
	Then \( g \) is continuous.
	Then, \( \eval{f}_{\mathbb R \setminus \qty{0}} \) is a homeomorphism from \( \mathbb R \setminus \qty{0} \) to \( \mathbb R^n \setminus \qty{f(0)} \), with inverse \( \eval{g}_{\mathbb R^n \setminus \qty{f(0)}} \).
	But \( \mathbb R \setminus \qty{0} \) is disconnected, but \( \mathbb R^n \setminus \qty{f(0)} \) is connected since it is path-connected.
	This is a contradiction.
\end{proof}
